package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.controller.admin.biz.AdminCategoryBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminCategoryListResp;
import com.wcs.exam.controller.admin.resp.AdminCategoryViewResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-分类
 *
 * @author wcs
 * @since 2025-03-11
 */
@Tag(name = "Admin-分类")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/category")
public class AdminCategoryController {

    @NotNull
    private final AdminCategoryBiz biz;

    @Operation(summary = "分类-列出")
    @GetMapping(value = "/list")
    public Result<List<AdminCategoryListResp>> list(@ModelAttribute AdminCategoryListReq req) {
        return biz.list(req);
    }

    @Operation(summary = "分类-添加")
    @OptLog(value = "分类-添加")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminCategorySaveReq req) {
        return biz.save(req);
    }

    @Operation(summary = "分类-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLogCache
    @GetMapping(value = "/view")
    public Result<AdminCategoryViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "分类-编辑")
    @OptLog(value = "分类-编辑", isUpdate = true)
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminCategoryEditReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "分类-更新状态")
    @OptLog(value = "分类-更新状态")
    @PutMapping(value = "/update/status")
    public Result<String> updateStatus(@RequestBody @Valid AdminCategoryUpdateStatusReq req) {
        return biz.updateStatus(req);
    }

    @Operation(summary = "分类-排序")
    @OptLog(value = "分类-排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminCategorySortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "分类-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLog(value = "分类-删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }
}
